<template>
  <div class="search-box">
    <el-form ref="ruleForm" :inline="true" :model="formInline">
      <el-form-item label="搜索：" prop="activityName">
        <el-select
          clearable
          filterable
          placeholder="请输入活动名称"
          v-model="formInline.activityName"
        >
          <el-option
            v-for="item in activeList"
            :key="item.id"
            :label="item.activityName"
            :value="item.activityName"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="状态：" prop="activityStatus">
        <el-select v-model="formInline.activityStatus" clearable>
          <el-option
            v-for="item in statusOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="时间：" prop="createTime">
        <el-date-picker
          style="width:400px"
          v-model="formInline.createTime"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item class="s-btn">
        <el-button type="success" icon="el-icon-search" @click="toSearch()">
          查询
        </el-button>
        <el-button type="success" plain @click="reset">
          重置
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { getActivityList } from '@/api/activityCenter/activityManage/collectPraise'
export default {
  watch: {
    'formInline.createTime': {
      handler(val) {
        this.formInline.startTime = val && val.length ? val[0] : ''
        this.formInline.endTime = val && val.length ? val[1] : ''
      },
      deep: true
    }
  },
  data() {
    return {
      formInline: {
        activityName: '',
        activityStatus: '',
        startTime: '',
        endTime: '',
        createTime: []
      },
      activeList: [],
      statusOptions: [
        { dictLabel: '全部', dictValue: '' },
        { dictLabel: '未开始', dictValue: 'NOT_STARTED' },
        { dictLabel: '进行中', dictValue: 'ONGOING' },
        { dictLabel: '已结束', dictValue: 'OVER' }
      ]
    }
  },
  mounted() {
    getActivityList((res) => {
      this.activeList = res
    })
  },
  methods: {
    /* 搜索 */
    toSearch() {
      const obj = Object.assign({}, this.formInline)
      delete obj.createTime
      this.$emit('toSearch', obj)
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>

<style lang="less" scoped></style>
